package com.qingcheng.service.impl;

import com.qingcheng.service.CategoryService;
import com.qingcheng.service.TbCategoryService;
import com.qingcheng.service.TbSkuService;
import com.qingcheng.service.TbSpuService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 戴金华
 *  实现InitializingBean接口的类会在启动时自动调用
 * @date 2019-11-23 11:31
 */
@Component
public class Init implements InitializingBean {

    @Autowired
    private TbCategoryService tbCategoryService;

    @Autowired
    private TbSkuService tbSkuService;

    @Autowired
    private TbSpuService spuService;

    @Autowired
    private TbCategoryService categoryService;

    /**
     * 缓存预热就是将数据提前加入到缓存中，当数据发生变更，再将最新的数据更新到缓
     * 存。
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("--缓存预热--");
        // 添加首页分类列表的缓存
        categoryService.saveCategoryTreeRedis();
        // 首页商品热卖缓存
        spuService.bestcache();
        // tbCategoryService.saveCategoryTreeToRedis();
        // 往es插入数据
        // tbSkuService.queryAll();
    }
}
